package dp;

import java.util.Arrays;

/**
 * leet-code(322) 零钱兑换
 *
 * @auther yang
 * @date 2022/4/22 15:02
 */
public class CoinChange {

    public static int solution(int[] coins, int amount) {
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, Character.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i <= amount; ++i) {
            for (int coin : coins) {
                if (i - coin >= 0)
                    dp[i] = Math.min(dp[i], dp[i - coin] + 1);
            }
        }
        return dp[amount] > amount ? -1 : dp[amount];
    }

}
